{layout name="public/layout" /}
{include file='yxnavbar'}


<link href="/resource/components/ueditors/themes/default/css/ueditor.css" type="text/css" rel="stylesheet">
<script type="text/javascript" charset="utf-8"  src="/resource/components/ueditors/ueditor.config.js?v=1"></script>
<script type="text/javascript" charset="utf-8" src="/resource/components/ueditors/ueditor.all.min.js?v=1"></script>
<script type="text/javascript" src="/resource/components/ueditors/lang/zh-cn/zh-cn.js"></script>
<script>
    var ueditorObj = {}
</script>

<div class="main">
    {include file='../../plugin/education/template/web/common_nav'}
    <div class="panel panel-default" role="tabpanel">
        <div class="panel-heading">编辑课程</div>
        <div class="panel-body">
            <form action="" method="post" class="form-horizontal" role="form" name="form2" id="form2">
                <input type="hidden" name="id" value="{$item['id']}"/>
                <input type="hidden" name="themeid" value="{$themeid}"/>
                {if $used_total>0}
                <input type="hidden" name="shangjiaid" value="{$item['shangjiaid']}"/>
                {/if}
                <div class="form-group">
                    <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label"><span style="color: red;">*</span>排序</label>
                    <div class="col-sm-8 col-xs-12">
                        <input type="number" class="form-control"  placeholder="默认排序" name="show_sort"  value="{$item['show_sort']}">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label"><span style="color: red;">*</span>所属商家</label>
                    <div class="col-sm-6 col-xs-12">
                        <select class="form-control" name="shangjiaid" {if $used_total>0}disabled{/if}>
                            <option value="0" {if empty($item['shangjiaid']) }selected="selected"{/if}>----------请选择商家----------</option>
                            {loop $shangjia  $val}
                            <option value="{$val['id']}" {if $item['shangjiaid'] == $val['id'] }selected="selected"{/if}>{$val['id']}-{$val['name']}</option>
                            {/loop}
                        </select>
                        {if $used_total>0}<span class="help-block" style="color: red;">该课程存在订单记录，无法更改商家</span>{/if}
                    </div>
                    <div class="col-sm-2 col-xs-12">
                        <a href="{php echo createWebUrl('shangjiaadd',array('themeid'=>$themeid));}" class="btn btn-success">编辑商家</a>
                    </div>
                </div>


                <!--编辑课程分类-->
                <div class="form-group">
                    <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label"><span style="color: red;">*</span>所属课程分类</label>
                    <div class="col-sm-6 col-xs-12">
                        <select class="form-control" name="shangjia_category_id" {if $used_total>0}disabled{/if}>
                            <option value="0" {if empty($item['shangjia_category_id']) }selected="selected"{/if}>----------请选择课程分类----------</option>
                            {loop $shangjia_category  $val}
                            <option value="{$val['ct_id']}" {if $item['shangjia_category_id'] == $val['ct_id'] }selected="selected"{/if}>{$val['ct_id']}-{$val['ct_name']}</option>
                            {/loop}
                        </select>
                        {if $used_total>0}<span class="help-block" style="color: red;">该课程存在订单记录，无法更改课程分类</span>{/if}
                    </div>
                </div>


<!--                <div class="form-group">-->
<!--                    <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label"><span style="color: red;">*</span>所属商家分类</label>-->
<!--                    <div class="col-sm-8 col-xs-12">-->
<!--                        <select class="form-control" name="shangjia_rule_id">-->
<!--                            <option value="0" {if empty($shangjia['shangjia_rule_id']) }selected="selected"{/if}>&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;请选择商家分类&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;</option>-->
<!--                            {loop $shangjia_category  $val}-->
<!--                            <option value="{$val['ct_id']}" {if $shangjia['shangjia_rule_id'] == $val['ct_id'] }selected="selected"{/if}>{$val['ct_id']}-{$val['ct_name']}</option>-->
<!--                            {/loop}-->
<!--                        </select>-->
<!--                    </div>-->
<!--                </div>-->



                <div class="form-group">
                    <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label"><span style="color: red;">*</span>课程名称</label>
                    <div class="col-sm-8 col-xs-12">
                        <input type="text" class="form-control"  placeholder="请输入课程名称" name="name"  value="{$item['name']}">
                        <span class="help-block">限20个字以内</span>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label"><span style="color: red;">*</span>课程头图</label>
                    <div class="col-sm-8 col-xs-12">
                        {php echo view_form_field_image('top_img',$item['top_img']);}
                        <span class="help-block">请上传330*330(宽*高)的高清图</span>
                    </div>
                </div>

<!--                <div class="form-group">-->
<!--                    <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label"><span style="color: red;">*</span>课程当前库存</label>-->
<!--                    <div class="col-sm-8 col-xs-12">-->
<!--                        <input type="number" class="form-control"  placeholder="请输入课程当前库存" name="qty"  value="{$item['qty']}">-->
<!--                    </div>-->
<!--                </div>-->
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">购买量</label>
                    <div class="col-sm-9 col-xs-12">
                        <div class="input-group">
                            <span class="input-group-addon">实际总量</span>
                            <input class="form-control"  name="selected_num" value="{$item['selected_num']}" disabled type="text">
                            <span class="input-group-addon">+</span>
                            <span class="input-group-addon"><span style="color: red;">今日虚拟</span></span>
                            <input class="form-control" placeholder="0" name="xuni_num" value="{$item['xuni_num']}" type="text">
                            <span class="input-group-addon">=</span>
                            <span class="input-group-addon">累计</span>
                            <input class="form-control"  value="{php echo $item['selected_num'] + $item['xuni_num'];}" disabled type="text">
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label">课程市场价格</label>
                    <div class="col-sm-8 col-xs-12">
                        <input type="number" class="form-control"  placeholder="请输入课程市场价格" name="price"  value="{$item['price']}">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 col-xs-12 control-label">活动可选</label>
                    <div class="col-sm-9 col-md-8 col-lg-8 col-xs-12">
                        <label class="radio-inline">
                            <input name="status" value="1" {if $item['status']==1 || !$item['status']} checked="checked"{/if} type="radio"> 可选
                        </label>
                        <label class="radio-inline">
                            <input name="status" value="0" {if  $item['status']===0  } checked="checked"{/if} type="radio">不可选
                        </label>

                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 col-xs-12 control-label">课程内容</label>
                    <div class="col-sm-8 col-xs-12">
                        {php echo view_ueditor('detail', $item['detail']);}

                    </div>
                </div>


                <div class="form-group" id="sub_upload" >
                    <div class="col-sm-12">
                        <input name="submit" onclick="addOrEditItem()" id="btnConfirm" type="button" value="提交" class="btn btn-primary col-lg-2">
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>


<script type="text/javascript">
    //新增\修改奖品 提交数据
    function addOrEditItem() {
        let postUrl = "{php echo createWebUrlPlugin('education.index.add',array('themeid'=>$themeid));}";
        let success_redirect = "{php echo createWebUrlPlugin('education',array('themeid'=>$themeid));}";
        let formData = $("#form2").serialize();
        $.ajax({
            url:postUrl,
            dataType:'json',
            method:'post',
            data:formData,
            success:function (e) {
                let status = e.status;
                let result = e.result;
                if (status!=1){
                    layer.msg(result.message)
                }else{
                    layer.msg(result.msg);
                    window.location.href = success_redirect;
                }
            },
            fail:function (err) {
                console.log(err)
            }
        })
    }
</script>
